<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <h1>抽奖系统（摸着良心抽奖）</h1>

    <button id="btn">请点击抽3等奖中奖人数</button>

    <h3>一等奖：</h3>
    <h3>二等奖：</h3>
    <h3>三等奖：</h3>


    <script src="../../JS基础/utils.js"></script>

    <script>
        let nameStr = ` 查丁予、刘安妮、向凌翔、林家玉、郑小鸿、罗明金、蔡青青、杨光辉、杜前、顾小平、曾福康、陈思颖、陈然、杨丹丹、涂禄垒、斯文帅、罗铭涛、廖安然、易国柱、黄鑫宇、吴洋、刘思憶、牛婉婷、李亚强、杨奕婧、张飞扬、易睿智、张鸿君、郑辉`;
        let nameArr = nameStr.split('、')
        let btn = document.getElementById('btn');
        let h3s = document.getElementsByTagName('h3');
        let count = 3;
        btn.onclick = function () {
            let num = prompt(`请输入${count}等奖的人数`);
            if (!(isNaN(num)) && num > 0 && num < nameArr.length) {
                let arr = [];
                //得到num个随机的下标
                for (let i = 0; i < num; i++) {
                    let index = createRandom(nameArr.length - 1);
                    arr.push(nameArr[index]);
                    nameArr.splice(index, 1)

                }
                h3s[count - 1].innerText += arr.join(',')
                count--;//进入下一次抽奖

                if (count > 0) {
                    btn.innerText = `请点击抽${count}等奖中奖人数`
                } else {
                    btn.innerText = '抽奖结束';
                    btn.disabled = true;
                }
            } else {
                alert('请重新输入');
            }




        }



    </script>

</body>

</html>